const jwt = require('jsonwebtoken')
const { JWT_SECRET } = require('./config/constant')
// 生成token
exports.getToken = (data, expiresIn) => {
  let token = jwt.sign(data, JWT_SECRET, {
    expiresIn,
  })
  return token
}

// 校验token
exports.verifyToken = (token) => {
  // token成功
  try {
    let data = jwt.verify(token, JWT_SECRET)
    return data
  } catch (err) {
    return false
  }
}
